﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Config;
using gfPage;
using gfLibrary;
using DBUtility;

namespace IYAKASAPortal.Recheck
{
    public partial class AJRecheckList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                btnSearch_Click(sender, e);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;

            string strSql = "select ID,JCLSH,HPHM,HPZL,JYLB,CLXXSJ,FJXM from VEHICLE_DISPATCH where (FJXM is not null or FJXM<>'') ";
                 strSql+="   and SUBSTRING(JCLSH,1,1)='A' ";
                 strSql += "    and JCZT_STATUS=4 ";
            if (strKeywords.Length > 0)
            {
                strSql += "  and ( ";
                strSql += " HPHM like '%" + strKeywords + "%'";
                strSql += " or VIN like '%" + strKeywords + "%'";
                strSql += " or JCLSH like '%" + strKeywords + "%')";
            }

            strSql += " order by CLXXSJ desc";

            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, AppConfig.g_strConnectionStringSqlClient, strSql, 20);

            for (int i = 0; i < m_dtTable.Rows.Count; i++)
            {
                string strFJXM = getJCXM(m_dtTable.Rows[i]["FJXM"].ToString());

                m_dtTable.Rows[i]["FJXM"] = strFJXM;
            }

            rptList.DataSource = m_dtTable;
            rptList.DataBind();

            m_dtTable.Dispose();
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;

            DataTable m_dtTable = GreatPager1.BindDataTablePage();
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
        }


        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected string getJCXM(string jcxm)
        {
            string result = "";
            if (!string.IsNullOrEmpty(jcxm))
            {
                string temp = jcxm.Substring(0, jcxm.Length - 1);
                if (temp.IndexOf(',') > 0)
                {
                    var item = temp.Split(',');
                    foreach (var i in item)
                    {
                        if (i.Contains("Z") == false)
                        {
                            result += getXMName(i.ToString()) + "、";
                        }
                    }
                }
                else
                {
                    result = getXMName(temp) + "、";
                }
                return result.Substring(0, result.Length - 1);
            }
            else
            {
                return result;
            }
        }

        protected string getXMName(string xm)
        {
            string result = "";
            result = DbHelper.GetValue("SELECT CON_CON from const_define where CON_CHNAME='jyxm' and CON_CODE='" + xm + "'");
            return result;
        }
    }
}